package com.situ.web.servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.situ.web.entity.User;

public class LogOutServlet extends HttpServlet {
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		HttpSession session = req.getSession();
		User user = (User)session.getAttribute("user");
		if (null != user) {
			session.invalidate();
			ServletContext servletContext = getServletContext();
			List<User> list = (List<User>) servletContext.getAttribute("onlineList");
			list.remove(list);
			servletContext.setAttribute("onlineList", list);
			resp.sendRedirect(req.getContextPath() + "/login.jsp");
		}
	}

}
